<template>
  <el-form ref="ruleFormRef" style="max-width: 600px" :model="ruleForm" :rules="rules" label-width="auto">
    <el-form-item label="用户名" prop="AccountName">
      <el-input v-model="ruleForm.AccountName" />
    </el-form-item>

      <!-- 哈哈哈我进来了 -->
    <el-form-item label="密码" prop="AccountPassword">
      <el-input v-model="ruleForm.AccountPassword" type="password" />
    </el-form-item>
    
    <el-form-item>
      <el-button type="primary" @click="submitForm(ruleFormRef)">
        登录
      </el-button>
      <el-button @click="resetForm(ruleFormRef)">取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
import axios from 'axios'
import router from '@/router'

interface RuleForm {
  AccountName: string
  AccountPassword: string
}

const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive<RuleForm>({
  AccountName: '',
  AccountPassword: '',
})

const locationOptions = ['Home', 'Company', 'School']

const rules = reactive<FormRules<RuleForm>>({
  AccountName: [
    { required: true, message: 'Please input Activity name', trigger: 'blur' },
  ],
  AccountPassword: [
    {
      required: true,
      message: 'Please select Activity zone',
      trigger: 'change',
    },
  ],
})

const submitForm = async (formEl: FormInstance | undefined) => {
  if (!formEl) return
  await formEl.validate((valid, fields) => {
    if (valid) {
      console.log('submit!',ruleForm)
      axios.get("http://localhost:5096/api/Login/Login",{params:ruleForm}).then(res=>{
        if(res.data.code==200){
          ElMessage.success(res.data.meg);
          router.push('/show')
        }
        else{
          ElMessage.error(res.data.meg);
        }
      })
    } else {
      console.log('error submit!', fields)
    }
  })
}

const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return
  formEl.resetFields()
}

const options = Array.from({ length: 10000 }).map((_, idx) => ({
  value: `${idx + 1}`,
  label: `${idx + 1}`,
}))
</script>
